package github.sf.mod.calculate;

import github.sf.mod.calculate.entity.Expression;
import github.sf.mod.calculate.entity.Interpreter;

/**
 * 实现一个简易版的计算器
 */
public class Calculate {
    //表达式
    //expression
    //expression = primitive op?
    public static void main(String[] args) {
//        String text = "3*3+2*5";
        String text = "3+2*5";
        CharStream charStream = new CharStream(text);
        Scanner scanner = new Scanner(charStream);
//        showALLToken(scanner);
        Parser parser = new Parser(scanner);
        Expression exp = parser.parse();
        exp.dump(0);
        Object visit = new Interpreter().visit(exp, null);
        System.out.println(visit);
    }

    public static void showALLToken(Scanner scanner) {
        Token t = scanner.next();
        while (t.getType() != TokenType.Eof) {
            System.out.println(t);
            t = scanner.next();
        }
    }
}
//        Token next = scanner.next();
//        System.out.println(text);
//        while (next.getType() != TokenType.Eof) {
//            System.out.println(next);
//            next = scanner.next();
//        }
//        String a = " ";
//        System.out.println(a.length());
//        System.out.println("-" + a.trim() + "-");
//        a = a.trim();
//        System.out.println(a.length());
